<?php
namespace AuctionCore\CarDealer;
use AuctionCore\AuctionOrder\AuOrderList;
use AuctionCore\CarResource\CarModel;
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//


/**
* "出价的车"列表
* @author       爱民
*/
class BidCarList extends AuOrderList
{

    private $dealer_id = null;

    public $condition = '';
    private $base_sql = null;
    private $count_sql = null;
    private $m = null;

    public function __construct($dealer_id) {
        $this->m = M();
        $this->dealer_id = $dealer_id;

        $query_sql = "SELECT o.order_id,o.order_no,o.bidding_end_time,o.bidding_best_dealer_id,o.trade_time
                ,o.fail_type,o.is_consult,o.consult_increase,o.bid_best_price,o.bidding_best_price
                ,o.`status`,o.first_pay_status,o.return_check_status,o.check_car_status,o.dealer_pay_status
                ,o.dealer_issue_status,o.reserve_price,o.success_price,o.success_dealer_id,o.pay_type
                ,c.car_id,c.car_no,c.plate_prefix,c.plate_suffix,c.car_color,c.car_status,c.first_reg_date
                ,c.transfer_limit,c.series_id,c.location_area,c.car_cc,c.turbo,c.gearbox,c.car_source
                ,db.last_bid_price,db.last_bidding_price
                ";

        $sql = " FROM au_order o INNER JOIN au_cars c ON c.car_id=o.car_id
                                    INNER JOIN au_dealer_bid db ON db.order_id=o.order_id
                                    WHERE o.status>=5 AND o.status !=301 AND db.dealer_id='".$this->dealer_id."'";
        $this->base_sql = $query_sql.$sql ;
        $this->count_sql = "select count(*) count ".$sql ;
    }


    /**
    * 获取列表结果
    * @param    int $ev_page_num    每页条数
    * @param    int $page    页码
    * @return   Object
    */
    public function get($ev_page_num, $page){

        $Model = $this->m;

        //拍单列表信息
        $sql = $this->base_sql;
        $sql .= $this->condition;
        $skip = ($page<2?0:$ev_page_num*($page-1)) ;
        $sql .= " order by o.bidding_end_time desc limit {$skip},{$ev_page_num}" ;
        $list = $Model->query($sql);
        $cm = new CarModel();
        $a = new \AuctionCore\Other\Address();

        foreach ($list as $key => $row) {
            //车型信息
            $series = $cm->get_model_by_id($row['series_id'],'series');
            $area = $a->get_province($row['location_area']);
            $list[$key]['model_info'] = '['.$area['city_name'].'] '.$series['name'] . ' ' . $row['car_cc'] . ($row['turbo'] ? 'T' : 'L') . ' ' . C('GEARBOX.' . $row['gearbox']);
            //最后投标价
            $list[$key]['my_bid_max_price'] = $row['last_bid_price'];;
            //最高竞标价
            $list[$key]['my_bidding_max_price'] = $row['last_bidding_price'];
            //是否竞得
            // $d = M("dealer_auctioned")->where("`dealer_id`={$dealer_id} AND `order_id`={$row['order_id']} AND `status`=0")->getField("dealer_id");
            // if($d==$dealer_id) $list[$key]['is_get'] = true;
        }
        return $list;
    }

    public function count(){
        $Model = $this->m;
        $sql = $this->count_sql;
        $sql .= " {$this->condition}";
        $r = $Model->query($sql);
        return $r[0]['count'];
    }

}

?>
